package edu.gatech.oad.antlab.person;

/**
 *  A simple class for person 2
 *  returns their name and a
 *  modified string 
 *
 * @author Amir
 * @version 1.2
 */
public class Person2 {
    /** Holds the persons real name */
    private String name;
	 	/**
	 * The constructor, takes in the persons
	 * name
	 * @param pname the person's real name
	 */
	 public Person2(String pname) {
	   name = pname;
	 }
	/**
	 * This method should take the string
	 * input and return its characters in
	 * random order.
	 * given "gtg123b" it should return
	 * something like "g3tb1g2".
	 *
	 * @param input the string to be modified
	 * @return the modified string
	 */
	private String calc(String input) {
		
	  // return String
	  String res;
	  
	  // create a character array to hold the random-ordered characters.
	  int n = input.length();
	  char[] charArr = new char[n];
	  
	  //initializing
	  String curr = input;
	  int seed;
	  
	  // loop to choose characters at random
	  for ( int i = 0; i < n; i++ ) {
		  //choose a random character from the substring and add it to the character array
		  seed = (int) Math.round(Math.random()*(curr.length()-1));
		  charArr[i] = curr.charAt(seed);
		  
		  //make a new substring that excludes the character that was just chosen
		  curr = curr.substring( 0, seed ) + curr.substring( seed + 1, curr.length() );
	  }
	  
	  // converting the character array to a string to return.
	  res = new String(charArr);
	  
	  return res;
	}
	/**
	 * Return a string rep of this object
	 * that varies with an input string
	 *
	 * @param input the varying string
	 * @return the string representing the 
	 *         object
	 */
	public String toString(String input) {
	  return name + calc(input);
	}
}
